<%@page import="java.util.GregorianCalendar"%>
<%@page import="com.sun.jmx.snmp.Timestamp"%>
<%@page import="com.metagurukul.metagranth.vo.User"%>
<%@page import="com.metagurukul.metagranth.vo.Tag"%>
<%@page import="com.metagurukul.metagranth.vo.MetaData"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"
	import="java.util.ArrayList,com.metagurukul.metagranth.vo.Question"%>

<%
	if (request.getAttribute("metaDataList") == null) {
		request.getRequestDispatcher("questions.do").forward(request,response);
	} else {
		ArrayList<MetaData> metaDataList = (ArrayList<MetaData>) request
				.getAttribute("metaDataList");
%>

	<table width="900px" border="0" align="center">
		<tr>
		<td colspan="3">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="3" class="question-header">
		<% if(metaDataList.size()>=15){ out.println("Latest 15 Questions....");
		} else {
			out.println("Questions");
		}
		%>
		
		
		</td>
	</tr>
	<tr>
		<td colspan="3" height="50px" valign="top"><hr />
		</td>
	</tr>
			
		<% if(metaDataList.size()>0){
			for (MetaData metaData : metaDataList) {
				Question question=metaData.getQuestion();
				ArrayList<Tag> tagList=metaData.getTagList();
				User user=metaData.getUser();
				String dateTime=question.getDateOfPost().toString();
				
				String date=dateTime.substring(0,10);
				String time=dateTime.substring(10);
				
		%>
		<tr>
			<td class="question-hyperlink" >
			<a href="question-discription.do?questionId=<%=question.getQuesId() %>"><%out.print(question.getTitle().substring(0,1).toUpperCase());
			
			if(question.getTitle().length()>1){
				if(question.getTitle().length()>60){
						out.println(question.getTitle().substring(1,60)+"...");
				}else {
					out.println(question.getTitle().substring(1,question.getTitle().length()));
				}
			}
			%></a>
			</td>
			<td align="right" valign="bottom" class="excerpt" width="200px">Posted By : <%=user.getName() %></td>
		</tr>
		<tr>
			<td>
			<%
			for(Tag tag:tagList){
				
				%>
				<a href="searchQuestionByTag.do?tagFilterId=<%=tag.getTagid()%>" class="post-tag" title="" rel="tag"><%=tag.getTagName()%></a>
				<%
			}
			%>
			</td>
			<td align="right" valign="bottom" class="excerpt">Time :<%=time.substring(0,time.length()-2)%> &nbsp;Date : <%=date%></td>
		</tr>
		<tr>
			<td colspan="2" style="border-top: 1px dotted #000000;" height="8px" valign="middle">&nbsp;</td>
		</tr>
		<%
			} 
		} else {
			%>
				<tr class="question-header">
						<td colspan="3" valign="top">No Question Available..!!</td>
					</tr>
				<tr>
						<td colspan="3" height="60px" valign="top">&nbsp;
						</td>
					</tr>
<%} %>
	</table>
<%
	request.removeAttribute("metaDataList");
	}
%>


